
package vu.cs.heuristieken;

public class Column extends ContainerEntity {
    protected House houseInstance;
    private   int   houseAvailability;

    public Column(Size size, House houseInstance) {
        super(size);
        this.houseInstance     = houseInstance;
        this.houseAvailability = (int) Math.floor((double) this.getDepth() / (double) (this.houseInstance.getDepth() + this.houseInstance.getVrijstand()));
        // There is still place for a last house if we don't include its vrijstand.
        if((this.getDepth() - (this.houseAvailability * (this.houseInstance.getDepth() + this.houseInstance.getVrijstand()))) > this.houseInstance.getDepth()) {
            this.houseAvailability++;
        }
    }

    public Class<?> getHouseType() {
        return this.houseInstance.getClass();
    }

    public int getHouseAvailability() {
        return this.houseAvailability;
    }

    public House getHouseInstance() {
        return this.houseInstance;
    }

    public Column clone() 
        throws CloneNotSupportedException {
        Column clone        = (Column) super.clone();
        clone.houseInstance = this.houseInstance.clone();
        return clone;
    }

    public void addPlacement(Placement placement) {
        int y = 0;
        for(Placement p : this.getPlacements()) {
            Entity entity = p.getEntity();
            if(entity instanceof House) {
                House house = (House) entity;
                y += house.getDepth() + house.getVrijstand();
            }
            else {
                y += entity.getDepth();
            }
        }
        super.addPlacement(new Placement(placement.getEntity(), new Position(placement.getPosition().getX(), y)));
    }
}
